home *** CD-ROM | disk | FTP | other *** search
- Path: news.itd.umich.edu!usenet
- From: Chris Lahey <clahey@umich.edu>
- Newsgroups: comp.lang.c
- Subject: Re: problems with a linked list
- Date: 25 Jan 1996 23:01:40 GMT
- Organization: University of Michigan
- Message-ID: <4e924k$o9c@lastactionhero.rs.itd.umich.edu>
- References: <1996Jan25.125329.23499@dcs.warwick.ac.uk>
- NNTP-Posting-Host: rep00703.reshall.umich.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.12 (X11; I; Linux 1.2.13 i586)
- X-URL: news:1996Jan25.125329.23499@dcs.warwick.ac.uk
-
- Sorry I can't quote you. This newsreader sucks. BUT:
-
-
- I think that your problem is that you are passing the value firstside to a
- function and then assigning a value to it and expecting the value to have
- changed when you return to main.
-
- One conceptual problem you may have is that you are using the same name in main
- and in your add_side function. C doesn't care (the add_side function can't see
- main's copy) but unless you pay close attention you may think that they are the
- same variable.
-
- When you pass the variable to add_side the C compiler creates code to send the
- value of first_side to the function. Even though the value in first_side is a
- pointer, the value is passed. You can change the data that the pointer points
- at but not if you change the pointer main won't see it.
-
- One possible solution would be to change main() so that it passes a pointer to
- a pointer to your struct and change add_side() correspondingly. Another would
- be a reorganization of the program, keeping the problem in mind (perhaps have
- add_side see the global variable. This is considered by some to be bad style.)
-
-